/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Hochschule Heilbronn
 * License Type: Academic
 */
package de.hhn.pmt.tour.u6;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;

public class StationDAO {
	public static Station loadStationByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadStationByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station getStationByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getStationByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadStationByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station getStationByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getStationByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Station) session.load(de.hhn.pmt.tour.u6.Station.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station getStationByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Station) session.get(de.hhn.pmt.tour.u6.Station.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Station) session.load(de.hhn.pmt.tour.u6.Station.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station getStationByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Station) session.get(de.hhn.pmt.tour.u6.Station.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryStation(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryStation(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryStation(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryStation(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station[] listStationByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listStationByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station[] listStationByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listStationByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryStation(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Station as Station");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryStation(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Station as Station");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Station", lockMode);
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station[] listStationByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		try {
			List list = queryStation(session, condition, orderBy);
			return (Station[]) list.toArray(new Station[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station[] listStationByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			List list = queryStation(session, condition, orderBy, lockMode);
			return (Station[]) list.toArray(new Station[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadStationByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByQuery(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadStationByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station loadStationByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		Station[] stations = listStationByQuery(session, condition, orderBy);
		if (stations != null && stations.length > 0)
			return stations[0];
		else
			return null;
	}

	public static Station loadStationByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		Station[] stations = listStationByQuery(session, condition, orderBy,
				lockMode);
		if (stations != null && stations.length > 0)
			return stations[0];
		else
			return null;
	}

	public static java.util.Iterator iterateStationByQuery(String condition,
			String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateStationByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateStationByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateStationByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateStationByQuery(
			PersistentSession session, String condition, String orderBy)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Station as Station");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateStationByQuery(
			PersistentSession session, String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Station as Station");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Station", lockMode);
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Station createStation() {
		return new de.hhn.pmt.tour.u6.Station();
	}

	public static boolean save(de.hhn.pmt.tour.u6.Station station)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().saveObject(
					station);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean delete(de.hhn.pmt.tour.u6.Station station)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().deleteObject(
					station);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(de.hhn.pmt.tour.u6.Station station)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.Tour[] lTours = station.tour.toArray();
			for (int i = 0; i < lTours.length; i++) {
				lTours[i].station.remove(station);
			}
			if (station.getCoordinates() != null) {
				station.getCoordinates().setStation(null);
			}

			return delete(station);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(
			de.hhn.pmt.tour.u6.Station station,
			org.orm.PersistentSession session) throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.Tour[] lTours = station.tour.toArray();
			for (int i = 0; i < lTours.length; i++) {
				lTours[i].station.remove(station);
			}
			if (station.getCoordinates() != null) {
				station.getCoordinates().setStation(null);
			}

			try {
				session.delete(station);
				return true;
			} catch (Exception e) {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean refresh(de.hhn.pmt.tour.u6.Station station)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.refresh(station);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean evict(de.hhn.pmt.tour.u6.Station station)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.evict(station);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

}
